package cn.lang.auth.service.impl;

import cn.lang.auth.mapper.MenuMapper;
import cn.lang.auth.service.IRoleService;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author Lang 1102076808@qq.com
 * @description 权限
 * @date 2020-06-21 12:28
 */
@Service
public class RoleServiceImpl implements IRoleService {

	@Resource
	private MenuMapper menuMapper;

	@Override
	public Set<String> getUserPermissions(long userId) {
		List<String> permsList = menuMapper.queryAllPerms(userId);
		Set<String> permsSet = new HashSet<>();
		for (String perms : permsList) {
			if (StringUtils.isBlank(perms)) {
				continue;
			}
			// 使用逗号分隔，每一个 perms
			permsSet.addAll(Arrays.asList(perms.trim().split(",")));
		}
		return permsSet;
	}
}
